﻿jQuery.cookie = function(name, value, options) {
    if (typeof value != 'undefined') { // name and value given, set cookie
        options = options || {};
        if (value === null) {
            value = '';
            options.expires = -1;
        }
        var expires = '';
        if (options.expires && (typeof options.expires == 'number' || options.expires.toUTCString)) {
            var date;
            if (typeof options.expires == 'number') {
                date = new Date();
                date.setTime(date.getTime() + (options.expires * 24 * 60 * 60 * 1000));
            } else {
                date = options.expires;
            }
            expires = '; expires=' + date.toUTCString(); // use expires attribute, max-age is not supported by IE
        }
        var path = options.path ? '; path=' + options.path : '';
        var domain = options.domain ? '; domain=' + options.domain : '';
        var secure = options.secure ? '; secure' : '';
        document.cookie = [name, '=', encodeURIComponent(value), expires, path, domain, secure].join('');
    } else { // only name given, get cookie
        var cookieValue = null;
        if (document.cookie && document.cookie != '') {
            var cookies = document.cookie.split(';');
            for (var i = 0; i < cookies.length; i++) {
                var cookie = jQuery.trim(cookies[i]);
                // Does this cookie string begin with the name we want?
                if (cookie.substring(0, name.length + 1) == (name + '=')) {
                    cookieValue = decodeURIComponent(cookie.substring(name.length + 1));
                    break;
                }
            }
        }
        return cookieValue;
    }
};


(function($) {
    $.fn.wresize = function(f) {
        version = '1.1';
        wresize = { fired: false, width: 0 };

        function resizeOnce() {
            if ($.browser.msie) {
                if (!wresize.fired) {
                    wresize.fired = true;
                }
                else {
                    var version = parseInt($.browser.version, 10);
                    wresize.fired = false;
                    if (version < 7) {
                        return false;
                    }
                    else if (version == 7) {
                        //a vertical resize is fired once, an horizontal resize twice  
                        var width = $(window).width();
                        if (width != wresize.width) {
                            wresize.width = width;
                            return false;
                        }
                    }
                }
            }
            return true;
        }
        function handleWResize(e) {
            if (resizeOnce()) {
                return f.apply(this, [e]);
            }
        }
        this.each(function() {
            if (this == window) {
                $(this).resize(handleWResize);
            }
            else {
                $(this).resize(f);
            }
        });
        return this;
    };

})(jQuery);

$(document).ready(function() {
    $(".btn").wrap("<div class='btnleft'></div>").after("<div class='btnright'></div>").addClass("btnbot");
    $('.btnleft').hover(function() {
        $(this).addClass("btnleftHover");
        $(this).find('.btnbot').addClass("btnbotHover");
        $(this).find('.btnright').addClass("btnrightHover");
    },
        function() {
            $(this).removeClass("btnleftHover");
            $(this).find('.btnright').removeClass("btnrightHover");
            $(this).find('.btnbot').removeClass("btnbotHover");
        });


    $(".btnwrite").wrap("<div class='btnleftwrite'></div>").after("<div class='btnrightwrite'></div>").addClass("btnbotwrite");
    $('.btnleftwrite').hover(function() {
        $(this).addClass("btnleftwriteHover");
        $(this).find('.btnbotwrite').addClass("btnbotwriteHover");
        $(this).find('.btnrightwrite').addClass("btnrightwriteHover");
    },
        function() {
            $(this).removeClass("btnleftwriteHover");
            $(this).find('.btnrightwrite').removeClass("btnrightwriteHover");
            $(this).find('.btnbotwrite').removeClass("btnbotwriteHover");
        });

    $(".btn_call").bind("click", function() {
        var controlName = $(this).attr("control");
        var phone = $("." + controlName).val();
        //        alert(phone);
        var win;
        if (window.opener != null) {
            win = window.opener;
        }
        else if (window.dialogArguments != null) {
            win = window.dialogArguments;
        }
        else if (window.parent != null) {
            win = window.parent;
        }
        if (win.parent.frameSoftPhone != null) {
            if (phone.length > 4) { 
                win.parent.frameSoftPhone.PlaceCallAndSetValue(phone);
            }
        }
    });


    $('#btnPrint').live("click", function() {
        window.print();
    });

    $('.row, .row2').hover(function() {
        $(this).addClass('hover');
    }, function() {
        $(this).removeClass('hover');
    }).bind('click', function() {
        $('.row, .row2').removeClass('selected');
        $(this).addClass('selected');
        $.cookie("row", $(this).attr("id"));
    });

    try {
        var row = $.cookie("row");
        $('#' + row).addClass('selected');
    }
    catch (ex) {
    }


    try {
        $('#divMain').height($(window).height() - 25);
        $('#divMain').width($(window).width() - 2);
    }
    catch (ex) {
    }

    try {
        $('#divMainPop').height($(window).height() - 27);
        $('#divMainPop').width($(window).width() - 2);
    }
    catch (ex) {
    }

    try {
        $('#divMainFAQ').height($(document).height() - 25);
        //    $('#divMainFAQ').width($(window).width() - 2);
    }
    catch (ex) {
    }

    try {
        $('#mainDiv').height($(window).height() - 1);
        //$('#mainDiv').width($(window).width() - 17);
        $('#leftDiv').height($(window).height() - 1);
    }
    catch (ex) {
    }

    //    $('#tTitle').width($(window).width());
    //    $('#tBodyMain').width($(window).width() - 37);
    //    $('#tBodyButton').width($(window).width() - 37);



    var ifameHeight = $(window).height();
    try {
        window.document.getElementById('frameLeft').style.height = ifameHeight + 'px';
        window.document.getElementById('frameFaqMain').style.height = ifameHeight + 'px';
    }
    catch (ex) {
    }

    try {
        window.document.getElementById('frameMainRightTop').style.height = ifameHeight + 'px';
        window.document.getElementById('frameMainLeftTop').style.height = (ifameHeight - 2) / 2 + 'px';
        window.document.getElementById('frameMainLeftButtom').style.height = (ifameHeight - 2) / 2 + 'px';
    }
    catch (ex) {
    };


    $(window).wresize(body_resize);


});

function reSubmitDisable(obj) {

    //obj.disabled = 'disabled';
}


function body_resize() {
    //    alert("resize event trigger");
    try {
        $('#divMain').height($(window).height() - 25);
        $('#divMain').width($(window).width() - 2);
    }
    catch (ex) {
    }

    try {
        $('#divMainPop').height($(window).height() - 27);
        $('#divMainPop').width($(window).width() - 2);
    }
    catch (ex) {
    }
    
    try {
        $('#divMainFAQ').height($(document).height() - 25);
        //        $('#divMainFAQ').width($(window).width() - 2);
    }
    catch (ex) {
    }
    
//    $('#tTitle').width($(window).width());
//    $('#tBodyMain').width($(window).width() - 37);
//    $('#tBodyButton').width($(window).width() - 37);

    try {
        $('#mainDiv').height($(window).height() - 1);
        $('#leftDiv').height($(window).height() - 1);
    }
    catch (ex) {
    }
    //$('#mainDiv').width($(window).width() - 2);


    var ifameHeight = $(window).height();
    try {
        window.document.getElementById('frameLeft').style.height = ifameHeight + 'px';
        window.document.getElementById('frameFaqMain').style.height = ifameHeight + 'px';
    }
    catch (ex) {
    }
    
    try {
        window.document.getElementById('frameMainRightTop').style.height = ifameHeight + 'px';
        window.document.getElementById('frameMainLeftTop').style.height = (ifameHeight - 2) / 2 + 'px';
        window.document.getElementById('frameMainLeftButtom').style.height = (ifameHeight - 2) / 2 + 'px';
    }
    catch (ex) {
    };


};


